import sun.audio.AudioPlayer;

import java.awt.image.BufferedImage;

public class Sheep extends TotalObject{
    int numberofbullets;//子弹数量

    int attackdirection;//攻击方向
    boolean isjumping;//是否正在跳跃
    int wudishijian;//无敌时间
    int attackmode;//攻击模式，0用近战武器，1用远程武器。
    boolean isattacking = false;//是否正在攻击
    int maxriseheight = 120;//一次跳跃高度
    boolean canjump = true;//是否允许跳跃

    public Sheep(int x, int y, int width, int height, int life,int speed) {
        super(x, y, width, height, life,speed);
        this.numberofbullets = 100;
    }

    public void jump(){
        if (riseheight==maxriseheight){
            isjumping = false;//停止跳跃
            letdrop();
        }
        else {
            y-=4;
            riseheight+=4;
        }
    }

    public void letjump(){
        if (isjumping||isdroping){
            maxriseheight = riseheight + 120;
            canjump = false;
        }
        else maxriseheight = 120;
        isjumping = true;
        isdroping = false;
    }

    public void letdrop(){
        isdroping = true;
    }

    @Override
    public void drop() {
        if (riseheight==0){
            isdroping = false;//停止下落
            canjump = true;
        }
        else {
            y+=4;
            riseheight-=4;
        }
    }

    @Override
    public void reducelife() {
        life--;
        if (!iswudi())wudishijian = 100;
    }

    @Override
    public BufferedImage getImage() {
        return null;
    }

    public BufferedImage getportraitImage() {
        return null;
    }


    int index = 0;
    int b = 0;




    public boolean iswudi(){
        return wudishijian>0;
    }

    //设置方向
    public void setDirection(int direction) {
        ismoving = true;
        this.movedirection = direction;
        if (movedirection==TotalObject.RIGHT||movedirection==TotalObject.LEFT)this.attackdirection = movedirection;
    }
    //设置攻击模式
    public void changeattackmode(){
        if (attackmode==TotalObject.nearattack)attackmode = TotalObject.farattack;
        else attackmode = TotalObject.nearattack;
    }

    public Attack attack() {
        if (attackmode==1){
            numberofbullets--;
            AudioPlayer.player.start(MyMusic.shoot);
        }
        isattacking = true;
        Attack attack = new Attack(x,y+10,attackdirection,attackmode);
        return attack;
    }

    public void step() {
        if (wudishijian!=0)wudishijian--;
        if (!ismoving)return;
        switch (movedirection){
            case TotalObject.RIGHT:
                x+=speed;
                break;
            case TotalObject.LEFT:
                x-=speed;
                break;
            case TotalObject.DOWN:
                if (riseheight>0){
                    y+=4;
                    riseheight-=4;
                    isjumping = false;
                    isdroping = true;
                }
                break;
        }


    }


}
